﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;
using BLL.Users;
using BLL.Users.Impl;
using Utils;

public partial class Page_Register_RegisterOfEnterprise : System.Web.UI.Page
{
    //用户管理业务操作对象
    private UserManageBO userManageBO;
    //用户编号
    private string userId;

    protected void Page_Load(object sender, EventArgs e)
    {
        userManageBO = new UserManageBOImpl();
        userId = WebUtil.GetIdentifier(Session["userId"]);

        //显示企业个人信息
        if (!IsPostBack)
        {
           Enterprise enterprise = (Enterprise)userManageBO.ShowDetail(userId);

           txtEditProfileEnterpriseAddress.Text = enterprise.EnterpriseAddress;
           txtEditProfileEnterpriseCity.Text = enterprise.EnterpriseCity;
           txtEditProfileEnterpriseEnterpriseName.Text = enterprise.EnterpriseName;
           txtEditProfileEnterpriseIntroduce.Text = enterprise.EnterpriseIntroduce;
           txtEditProfileEnterprisePhone.Text = enterprise.EnterprisePhone;
           txtEditProfileEnterprisePostalCode.Text = enterprise.EnterprisePostalCode;

           listEditProfileEnterpriseEnterpriseType.SelectedValue = enterprise.EnterpriseType;
           listEditProfileEnterpriseState_Province.SelectedValue = enterprise.EnterpriseProvince; 
       }

    }



    protected void btnEditProfileEnterpriseSubmit_Click(object sender, ImageClickEventArgs e)
    {
        //数据收集
        string address = filter(txtEditProfileEnterpriseAddress.Text);
        string city = filter(txtEditProfileEnterpriseCity.Text);
        string name = filter(txtEditProfileEnterpriseEnterpriseName.Text);
        string introduce = filter(txtEditProfileEnterpriseIntroduce.Text);
        string phone = filter(txtEditProfileEnterprisePhone.Text);
        string postalCode = filter(txtEditProfileEnterprisePostalCode.Text);
        string type = filter(listEditProfileEnterpriseEnterpriseType.SelectedValue);
        string province = filter(listEditProfileEnterpriseState_Province.SelectedValue);

        ////输入校验
        //if (address.Length > 30 || address.Length < 6)
        //{
        //    Response.Write(WebUtil.GetTips("企业名称长度必须为6-30"));
        //    return;
        //}
        ////else if ()
        ////{

        ////}
        //实体封装
        Enterprise enterprise = new Enterprise
        {
            EnterpriseId = userId,
            EnterpriseAddress=address,
            EnterpriseCity = city,
            EnterpriseName=name,
            EnterpriseIntroduce = introduce,
            EnterprisePhone=phone,
            EnterprisePostalCode=postalCode,
            EnterpriseType=type,
            EnterpriseProvince=province
        };
        //接口调用
        bool result = userManageBO.EidtProfile(userId, enterprise);
        //显示结果
        if (result)
        {
            Response.Write(WebUtil.GetTipsAndRedirect("Edit Profile Success!", Request.Url, "Home.aspx"));
        }
        else
        {
            Response.Write(WebUtil.GetTipsAndRedirect("Edit Profile Failure!", "EditProfileEnterprise.aspx"));
        }
    }

    private string filter(object inputStr)
    {
        if (inputStr == null) return "";
        else 
            return inputStr.ToString();
    }
}